package abel.wlmr.model.type;

import abel.wlmr.model.WlmrField;

public class MeterStatus3Field extends WlmrField {

    private byte storageException;
    private byte parityException;
    private byte wirelessException;
    private byte magnetAttack;

    public MeterStatus3Field() {
        super(2);
    }

    @Override
    public int getValue() {
        return storageException | parityException << 1
            | wirelessException << 2 | magnetAttack << 3;
    }

    @Override
    public void parseValue(int v) {
        storageException = (byte) (v & 1);
        parityException = (byte) ((v & 2) >> 1);
        wirelessException = (byte) ((v & 4) >> 2);
        magnetAttack = (byte) ((v & 8) >> 3);
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return String.format("{storageException:%s, parityException:%s, wirelessException:%s, magnetAttack:%s}",
            storageException, parityException, wirelessException, magnetAttack);
    }

    /**
     * @return the storageException
     */
    public byte getStorageException() {
        return storageException;
    }

    /**
     * @param v
     *            the storageException to set
     */
    public void setStorageException(byte v) {
        if (v != 0 && v != 1) {
            throw new IllegalArgumentException("v should be [0,1]");
        }

        this.storageException = v;
    }

    /**
     * @return the parityException
     */
    public byte getParityException() {
        return parityException;
    }

    /**
     * @param v
     *            the parityException to set
     */
    public void setParityException(byte v) {
        if (v != 0 && v != 1) {
            throw new IllegalArgumentException("v should be [0,1]");
        }

        this.parityException = v;
    }

    /**
     * @return the wirelessException
     */
    public byte getWirelessException() {
        return wirelessException;
    }

    /**
     * @param v
     *            the wirelessException to set
     */
    public void setWirelessException(byte v) {
        if (v != 0 && v != 1) {
            throw new IllegalArgumentException("v should be [0,1]");
        }

        this.wirelessException = v;
    }

    /**
     * @return the magnetAttack
     */
    public byte getMagnetAttack() {
        return magnetAttack;
    }

    /**
     * @param v
     *            the magnetAttack to set
     */
    public void setMagnetAttack(byte v) {
        if (v != 0 && v != 1) {
            throw new IllegalArgumentException("v should be [0,1]");
        }

        this.magnetAttack = v;
    }

}
